package Servlet;

import Utility.Utility;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "delete", value = "/delete")
public class Delete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();

        String id = req.getParameter("id");
        System.out.println(id);
        String sql = "delete from student where id=?";
        int i = Utility.delete(sql,id);
        if(i>0){
            out.write("删除成功！");
        }else{
            out.write("删除失败！");
        }
        out.write("<a href=\"http://localhost:8080/stu\">返回</a>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
